#include <stdio.h>
#include <string.h>
#include <stdlib.h>

static long string_hash(register unsigned char *p, int size) {
    register int len;
    register long x;

    len = size;
    x = *p << 7;
    while (--len >= 0) {
        x = (100003*x) ^ *p++;
    }

    x ^= size;

    return x;
}


static long string_hash2(register char *p, int size) {
    register unsigned long x = 0;
    register int len;

    if (size == 0) {
        return 0;
    }

    len = (size+1) >> 1;
    while (len--) {
// printf("x >> 14: %ld => %ld\n", x, x >> 14);
        x += (x>>14) + (*p++ * 0xd2d84a61);
    }
// printf("x >> 14: %ld => %ld\n", x, x >> 14);
// printf("size*0xd2d84a61 = %u\n", size*0xd2d84a61);
    x += (x>>14) + (size*0xd2d84a61);
    
    return x;
}


int main2(int argc, char **argv) {
    long x = 0;

    if (argc < 2) {
        return 127;
    }

    x = string_hash2(argv[1], strlen(argv[1]));
    printf("[%s] => %lu\n", argv[1], x);
    printf("%lu", x);

    return 0;
}


int main(int argc, char **argv) {
    long x = 0;
    char data[BUFSIZ + 1];

    while (fgets(data, BUFSIZ, stdin) != NULL) {
        data[strlen(data) - 1] = '\0';
        //printf("%s: %d\n", data, strlen(buff));

        printf("%lu\n", string_hash(data, strlen(data)));
    }
}


